package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.common.log.annotation.Log;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "权限角色接口")
@RestController
@RequestMapping(value =  "/admin/system/sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;


    /**
     * 查询所有角色
     * @return
     */
    @Operation(summary = "查询所有角色")
    @GetMapping("/findAllRoles/{userId}")
    public Result findAllRoles(@PathVariable("userId") Long userId) {
        Map<String, Object> map = sysRoleService.findAll(userId);
        return Result.build(map, ResultCodeEnum.SUCCESS);
    }
    /**
     * 角色列表的方法
     * @param sysRoleDto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Operation(summary = "分页查询信息")
    @PostMapping("/findBypage/{pageNum}/{pageSize}")
    public Result findBypage(@RequestBody SysRoleDto sysRoleDto,
                                              @PathVariable("pageNum") Integer pageNum,
                                              @PathVariable("pageSize") Integer pageSize) {
      PageInfo<SysRole> pageInfo =  sysRoleService.findBypage(sysRoleDto, pageNum, pageSize);
      return Result.build(pageInfo, ResultCodeEnum.SUCCESS);

    }

    /**
     * 角色添加
     * @param sysRole
     * @return
     */

    @Operation(summary = "角色添加")
    @PostMapping("/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "角色修改")
    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "角色删除")
    @DeleteMapping("/deleteById/{roleId}")
    public Result deleteById(@PathVariable("roleId") String roleId) {
        sysRoleService.deleteById(roleId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
